home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / library / reqtlsdv.lha / ReqTools / Glue / GCC / gcc_glue.lha / demo.c next >
C/C++ Source or Header  |  1994-04-21  |  16KB  |  516 lines

  1. /********************************
  2. *                *
  3. *  reqtools.library (V38)    *
  4. *                *
  5. *  Release 2.0            *
  6. *                *
  7. *  (c) 1991-1993 Nico François    *
  8. *                *
  9. *  demo.c            *
  10. *                *
  11. *  This source is public domain    *
  12. *  in all respects.        *
  13. *                *
  14. *********************************/
  15.  
  16. /********************************
  17. *                *
  18. *  GCC demo            *
  19. *                *
  20. *  (c) 1993 Marc Duponcheel    *
  21. *                *
  22. *  addded: hook support for    *
  23. *       small data        *
  24. *                *
  25. *  (c) 1994 Gunther Nikl    *
  26. *                *
  27. *********************************/
  28.  
  29. #include <exec/types.h>
  30. #include <exec/memory.h>
  31. #include <exec/execbase.h>
  32. #include <libraries/dos.h>
  33. #include <libraries/reqtools.h>
  34. #include <intuition/intuition.h>
  35.  
  36. #ifndef __GCC__
  37. #include <proto/dos.h>
  38. #include <proto/exec.h>
  39. #include <proto/reqtools.h>
  40. #else
  41. #include <dos/exall.h>
  42. #ifndef INLINE
  43. #include <clib/dos_protos.h>
  44. #include <clib/exec_protos.h>
  45. #include <clib/reqtools_protos.h>
  46. #else
  47. #include <inline/dos.h>
  48. #include <inline/exec.h>
  49. #include <inline/reqtools.h>
  50. #endif
  51. #endif
  52.  
  53. extern struct ExecBase *SysBase;
  54. struct ReqToolsBase *ReqToolsBase;
  55.  
  56. #define REG register
  57. #define main _main
  58.  
  59. #ifdef DOHOOKS
  60. #ifndef __GCC__
  61. /* Callback functions
  62.     Define DOHOOKS when you compile to activate these filter functions */
  63.  
  64. BOOL __asm __saveds file_filterfunc (
  65.     REG __a0 struct Hook *, REG __a2 struct rtFileRequester *,
  66.     REG __a1 struct FileInfoBlock *
  67.     );
  68. BOOL __asm __saveds font_filterfunc (
  69.     REG __a0 struct Hook *, REG __a2 struct rtFontRequester *,
  70.     REG __a1 struct TextAttr *
  71.     );
  72. BOOL __asm __saveds vol_filterfunc (
  73.     REG __a0 struct Hook *, REG __a2 struct rtFileRequester *,
  74.     REG __a1 struct rtVolumeEntry *
  75.     );
  76. #else
  77. void main_filterfunc ();
  78. BOOL file_filterfunc (struct Hook *,struct rtFileRequester *,struct FileInfoBlock *);
  79. BOOL font_filterfunc (struct Hook *,struct rtFontRequester *,struct TextAttr *);
  80. BOOL vol_filterfunc  (struct Hook *,struct rtFileRequester *,struct rtVolumeEntry *);
  81. #endif __GCC__
  82. #endif DOHOOKS
  83.  
  84. static ULONG undertag[] = { RT_Underscore, '_', TAG_END };
  85.  
  86. void myputs (char *str)
  87. {
  88.     Write (Output(), str, strlen(str));
  89. }
  90.  
  91. #ifndef __GCC__
  92. main()
  93. #else
  94. int main()
  95. #endif
  96. {
  97.     struct rtFileRequester *filereq;
  98.     struct rtFontRequester *fontreq;
  99.     struct rtScreenModeRequester *scrmodereq;
  100.     struct rtFileList *flist, *tempflist;
  101.  
  102.     char buffer[128], filename[34];
  103.     long longnum, ret, color;
  104.  
  105. #ifdef DOHOOKS
  106.     struct Hook filterhook;
  107. #ifdef __GCC__
  108.         filterhook.h_Entry = (ULONG (*)())main_filterfunc;
  109. #endif
  110. #endif
  111.     if (!(ReqToolsBase = (struct ReqToolsBase *)OpenLibrary (REQTOOLSNAME, REQTOOLSVERSION))) {
  112.         myputs ("You need reqtools.library V38 or higher!\n"
  113.             "Please install it in your Libs: drirectory.\n");
  114.         return (0);
  115.         }
  116.  
  117.     rtEZRequest ("ReqTools 2.0 Demo\n"
  118.                  "~~~~~~~~~~~~~~~~~\n"
  119.                      "'reqtools.library' offers several\n"
  120.                      "different types of requesters:",
  121.                      "Let's see them", NULL, NULL);
  122.  
  123.     rtEZRequest ("NUMBER 1:\nThe larch :-)", "Be serious!", NULL, NULL);
  124.  
  125.     rtEZRequest ("NUMBER 1:\nString requester\nfunction: rtGetString()",
  126.                      "Show me", NULL, NULL);
  127.  
  128.     strcpy (buffer, "A bit of text");
  129.     if (!rtGetString (buffer, 127, "Enter anything:", NULL, TAG_END))
  130.         rtEZRequest ("You entered nothing :-(", "I'm sorry", NULL, NULL);
  131.     else
  132.         rtEZRequest ("You entered this string:\n'%s'.",
  133.                          "So I did", NULL, NULL, buffer);
  134.  
  135.     ret = rtGetString (buffer, 127, "Enter anything:", NULL,
  136.                              RTGS_GadFmt, " _Ok |New _2.0 feature!|_Cancel",
  137.                              RTGS_TextFmt,
  138.                                  "These are two new features of ReqTools 2.0:\n"
  139.                                   "Text above the entry gadget and more than\n"
  140.                                   "one response gadget.",
  141.                      TAG_MORE, undertag);
  142.     if (ret == 2)
  143.         rtEZRequest ("Yep, this is a new\nReqTools 2.0 feature!",
  144.                          "Oh boy!", NULL, NULL);
  145.  
  146.     ret = rtGetString (buffer, 127, "Enter anything:", NULL,
  147.                              RTGS_GadFmt, " _Ok |_Abort|_Cancel",
  148.                              RTGS_TextFmt,
  149.                                  "New is also the ability to switch off the\n"
  150.                                   "backfill pattern.  You can also center the\n"
  151.                                   "text above the entry gadget.\n"
  152.                                   "These new features are also available in\n"
  153.                                   "the rtGetLong() requester.",
  154.                              RTGS_BackFill, FALSE,
  155.                              RTGS_Flags, GSREQF_CENTERTEXT|GSREQF_HIGHLIGHTTEXT,
  156.                              TAG_MORE, undertag);
  157.     if (ret == 2)
  158.         rtEZRequest ("What!! You pressed abort!?!\nYou must be joking :-)",
  159.                          "Ok, Continue", NULL, NULL);
  160.                          
  161.  
  162.     rtEZRequest ("NUMBER 2:\nNumber requester\nfunction: rtGetLong()",
  163.                      "Show me", NULL, NULL);
  164.  
  165.     if (!rtGetLong (&longnum, "Enter a number:", NULL,
  166.                          RTGL_ShowDefault, FALSE,
  167.                          RTGL_Min, 0, RTGL_Max, 666,TAG_END))
  168.         rtEZRequest ("You entered nothing :-(",
  169.                          "I'm sorry", NULL, NULL);
  170.     else
  171.         rtEZRequest ("The number you entered was:\n%ld%s",
  172.                          "So it was", NULL, NULL, longnum,
  173.                             (longnum == 666) ? " (you devil! :)" : "");
  174.  
  175.     rtEZRequest ("NUMBER 3:\nMessage requester, the requester\n"
  176.                      "you've been using all the time!\nfunction: rtEZRequest()",
  177.                      "Show me more", NULL, NULL);
  178.  
  179.     rtEZRequest ("Simplest usage: some body text and\na single centered gadget.",
  180.                      "Got it", NULL, NULL);
  181.  
  182.     while (!rtEZRequest ("You can also use two gadgets to\n"
  183.                                 "ask the user something.\n"
  184.                                 "Do you understand?", "Of course|Not really",
  185.                                 NULL, NULL))
  186.         rtEZRequest ("You are not one of the brightest are you?\n"
  187.                          "We'll try again...",
  188.                          "Ok", NULL, NULL);
  189.  
  190.     rtEZRequest ("Great, we'll continue then.", "Fine", NULL, NULL);
  191.  
  192.     switch (rtEZRequest ("You can also put up a requester with\n"
  193.                                 "three choices.\n"
  194.                                 "How do you like the demo so far ?",
  195.                                 "Great|So so|Rubbish", NULL, NULL)) {
  196.         case FALSE:
  197.             rtEZRequest ("Too bad, I really hoped you\nwould like it better.",
  198.                              "So what", NULL, NULL);
  199.             break;
  200.         case TRUE:
  201.             rtEZRequest ("I'm glad you like it so much.", "Fine", NULL, NULL);
  202.             break;
  203.         case 2:
  204.             rtEZRequest ("Maybe if you run the demo again\n"
  205.                              "you'll REALLY like it.",
  206.                              "Perhaps", NULL, NULL);
  207.             break;
  208.         }
  209.  
  210.     ret = rtEZRequestTags ("The number of responses is not limited to three\n"
  211.                                   "as you can see.  The gadgets are labeled with\n"    
  212.                                   "the return code from rtEZRequest().\n"
  213.                                   "Pressing Return will choose 4, note that\n"
  214.                                   "4's button text is printed in boldface.",
  215.                                   "1|2|3|4|5|0", NULL, NULL,
  216.                                   RTEZ_DefaultResponse, 4, TAG_END);
  217.     rtEZRequest ("You picked '%ld'.", "How true", NULL, NULL, ret);
  218.  
  219.     rtEZRequestTags ("New for Release 2.0 of ReqTools (V38) is\n"
  220.                           "the possibility to define characters in the\n"
  221.                           "buttons as keyboard shortcuts.\n"
  222.                           "As you can see these characters are underlined.\n"
  223.                           "Pressing shift while still holding down the key\n"
  224.                           "will cancel the shortcut.\n"
  225.                           "Note that in other requesters a string gadget may\n"
  226.                           "be active.  To use the keyboard shortcuts there\n"
  227.                           "you have to keep the Right Amiga key pressed down.",
  228.                           "_Great|_Fantastic|_Swell|Oh _Boy",
  229.                           NULL, NULL,
  230.                           RT_Underscore, '_', TAG_END);
  231.  
  232.     rtEZRequest (
  233.         "You may also use C-style formatting codes in the body text.\n"
  234.         "Like this:\n\n"
  235.         "'The number %%ld is written %%s.' will give:\n\n"
  236.         "The number %ld is written %s.\n\n"
  237.         "if you also pass '5' and '\"five\"' to rtEZRequest().",
  238.         "_Proceed", NULL, (struct TagItem *)&undertag, 5, "five");
  239.  
  240.     if (rtEZRequestTags ("It is also possible to pass extra IDCMP flags\n"
  241.                                "that will satisfy rtEZRequest(). This requester\n"
  242.                                "has had DISKINSERTED passed to it.\n"
  243.                                "(Try inserting a disk).",
  244.                                "_Continue", NULL, NULL,
  245.                                RT_IDCMPFlags, DISKINSERTED,
  246.                                 RT_Underscore, '_', TAG_END)
  247.                                & DISKINSERTED)
  248.         rtEZRequest ("You inserted a disk.", "I did", NULL, NULL);
  249.     else
  250.         rtEZRequest ("You used the 'Continue' gadget\n"
  251.                          "to satisfy the requester.", "I did", NULL, NULL);
  252.  
  253.     rtEZRequestTags ("Finally, it is possible to specify the position\n"
  254.                           "of the requester.\n"
  255.                           "E.g. at the top left of the screen, like this.\n"
  256.                           "This works for all requesters, not just rtEZRequest()!",
  257.                           "_Amazing", NULL, NULL,
  258.                           RT_ReqPos, REQPOS_TOPLEFTSCR,
  259.                           RT_Underscore, '_', TAG_END);
  260.  
  261.     rtEZRequestTags ("Alternatively, you can center the\n"
  262.                           "requester on the screen.\n"
  263.                           "Check out 'reqtools.doc' for all the possibilities.",
  264.                           "I'll do that", NULL, NULL,
  265.                           RT_ReqPos, REQPOS_CENTERSCR, TAG_END);
  266.  
  267.     rtEZRequestTags ("NUMBER 4:\nFile requester\n"
  268.                           "function: rtFileRequest()",
  269.                           "_Demonstrate", NULL, NULL, RT_Underscore, '_', TAG_END);
  270.  
  271.     if ((filereq = rtAllocRequestA (RT_FILEREQ, NULL))) {
  272.  
  273. #ifdef DOHOOKS
  274. #ifndef __GCC__
  275.         filterhook.h_Entry = (ULONG (*)())file_filterfunc;
  276. #else
  277.         filterhook.h_SubEntry = (ULONG (*)())file_filterfunc;
  278. #endif
  279. #endif
  280.  
  281.         filename[0] = 0;
  282.         if (rtFileRequest (filereq, filename, "Pick a file",
  283. #ifdef DOHOOKS
  284.                                  RTFI_FilterFunc, &filterhook,
  285. #endif
  286.                                  TAG_END))
  287.             rtEZRequest ("You picked the file:\n'%s'\nin directory:\n'%s'",
  288.                              "Right", NULL, NULL, filename, filereq->Dir);
  289.         else
  290.             rtEZRequest ("You didn't pick a file.", "No", NULL, NULL);
  291.  
  292.         rtEZRequestTags ("The file requester has the ability\n"
  293.                               "to allow you to pick more than one\n"
  294.                               "file (use Shift to extend-select).\n"
  295.                               "Note the extra gadgets you get.",
  296.                               "_Interesting", NULL, NULL, RT_Underscore, '_', TAG_END);
  297.  
  298.         flist = rtFileRequest (filereq, filename, "Pick some files",
  299.                                       RTFI_Flags, FREQF_MULTISELECT, TAG_END);
  300.         if (flist) {
  301.             rtEZRequest ("You selected some files, this is\n"
  302.                              "the first one:\n"
  303.                              "'%s'\n"
  304.                              "All the files are returned as a linked\n"
  305.                              "list (see demo.c and reqtools.h).",
  306.                              "Aha", NULL, NULL, flist->Name);
  307.             /* Traverse all selected files */
  308.             /*
  309.             tempflist = flist;
  310.             while (tempflist) {
  311.                 DoSomething (tempflist->Name, tempflist->StrLen);
  312.                 tempflist = tempflist->Next;
  313.                 }
  314.             */
  315.             /* Free filelist when no longer needed! */
  316.             rtFreeFileList (flist);
  317.             }
  318.  
  319.         rtFreeRequest (filereq);
  320.         }
  321.     else
  322.         rtEZRequest ("Out of memory!", "Oh boy!", NULL, NULL);
  323.  
  324.  
  325.     rtEZRequestTags ("The file requester can be used\n"
  326.                           "as a directory requester as well.",
  327.                           "Let's _see that", NULL, NULL, RT_Underscore, '_', TAG_END);
  328.  
  329.     if ((filereq = rtAllocRequestA (RT_FILEREQ, NULL))) {
  330.         if (rtFileRequest (filereq, filename, "Pick a directory",
  331.                                  RTFI_Flags, FREQF_NOFILES, TAG_END))
  332.             rtEZRequest ("You picked the directory:\n'%s'",
  333.                              "Right", NULL, NULL, filereq->Dir);
  334.         else
  335.             rtEZRequest ("You didn't pick a directory.", "No", NULL, NULL);
  336.  
  337.         rtFreeRequest (filereq);
  338.         }
  339.     else
  340.         rtEZRequest ("Out of memory!", "Oh boy!", NULL, NULL);
  341.  
  342.     rtEZRequest ("NUMBER 5:\nFont requester\n"
  343.                      "function: rtFontRequest()",
  344.                      "Show", NULL, NULL);
  345.  
  346.     if ((fontreq = rtAllocRequestA (RT_FONTREQ, NULL))) {
  347.  
  348.         fontreq->Flags = FREQF_STYLE|FREQF_COLORFONTS;
  349.  
  350. #ifdef DOHOOKS
  351. #ifndef __GCC__
  352.         filterhook.h_Entry = (ULONG (*)())font_filterfunc;
  353. #else
  354.         filterhook.h_SubEntry = (ULONG (*)())font_filterfunc;
  355. #endif
  356. #endif
  357.  
  358.         if (rtFontRequest (fontreq, "Pick a font",
  359. #ifdef DOHOOKS
  360.                                  RTFO_FilterFunc, &filterhook,
  361. #endif
  362.                                  TAG_END))
  363.             rtEZRequest ("You picked the font:\n'%s'\nwith size:\n'%ld'",
  364.                              "Right", NULL, NULL,
  365.                              fontreq->Attr.ta_Name, fontreq->Attr.ta_YSize);
  366.         else
  367.             rtEZRequestTags ("You canceled.\nWas there no font you liked ?",
  368.                                   "_Nope", NULL, NULL, RT_Underscore, '_', TAG_END);
  369.  
  370.         rtFreeRequest (fontreq);
  371.         }
  372.     else
  373.         rtEZRequest ("Out of memory!", "Oh boy!", NULL, NULL);
  374.  
  375.     rtEZRequestTags ("NUMBER 6:\nPalette requester\n"
  376.                           "function: rtPaletteRequest()",
  377.                           "_Proceed", NULL, NULL, RT_Underscore, '_', TAG_END);
  378.     color = rtPaletteRequest ("Change palette", NULL, TAG_END);
  379.     if (color == -1)
  380.         rtEZRequest ("You canceled.\nNo nice colors to be picked ?",
  381.                          "Nah", NULL, NULL);
  382.     else
  383.         rtEZRequest ("You picked color number %ld.", "Sure did",
  384.                          NULL, NULL, color);
  385.     rtEZRequestTags ("NUMBER 7: (ReqTools 2.0)\n"
  386.                           "Volume requester\n"
  387.                           "function: rtFileRequest() with\n"
  388.                           "          RTFI_VolumeRequest tag.",
  389.                           "_Show me", NULL, NULL, RT_Underscore, '_', TAG_END);
  390.  
  391.     if ((filereq = rtAllocRequestA (RT_FILEREQ, NULL))) {
  392.  
  393. #ifdef DOHOOKS
  394. #ifndef __GCC__
  395.         filterhook.h_Entry = (ULONG (*)())vol_filterfunc;
  396. #else
  397.         filterhook.h_SubEntry = (ULONG (*)())vol_filterfunc;
  398. #endif
  399. #endif
  400.  
  401.         if (rtFileRequest (filereq, NULL, "Pick a volume",
  402. #ifdef DOHOOKS
  403.                                  RTFI_FilterFunc, &filterhook,
  404. #endif
  405.                                  RTFI_VolumeRequest, 0, TAG_END))
  406.             rtEZRequest ("You picked the volume:\n'%s'",
  407.                              "Right", NULL, NULL, filereq->Dir);
  408.         else
  409.             rtEZRequest ("You didn't pick a volume.", "I did not", NULL, NULL);
  410.  
  411.         rtFreeRequest (filereq);
  412.         }
  413.     else
  414.         rtEZRequest ("Out of memory!", "Oh boy!", NULL, NULL);
  415.  
  416.     rtEZRequestTags ("NUMBER 8: (ReqTools 2.0)\n"
  417.                           "Screen mode requester\n"
  418.                           "function: rtScreenModeRequest()\n"
  419.                           "Only available on Kickstart 2.0!",
  420.                           "_Proceed", NULL, NULL, RT_Underscore, '_', TAG_END);
  421.     if (SysBase->LibNode.lib_Version < 37)
  422.         rtEZRequestTags ("Your Amiga doesn't seem to have\n"
  423.                               "Kickstart 2.0 in ROM so I am not\n"
  424.                               "able to show you the Screen mode\n"
  425.                               "requester.\n"
  426.                               "So upgrade to 2.0 *now* :-)",
  427.                               "_Allright", NULL, NULL, RT_Underscore, '_', TAG_END);
  428.     else {
  429.         if ((scrmodereq = rtAllocRequestA (RT_SCREENMODEREQ, NULL))) {
  430.  
  431.             if (rtScreenModeRequest (scrmodereq, "Pick a screen mode:",
  432.                                              RTSC_Flags, SCREQF_DEPTHGAD|SCREQF_SIZEGADS|
  433.                                                  SCREQF_AUTOSCROLLGAD|SCREQF_OVERSCANGAD,
  434.                                               TAG_END))
  435.                 rtEZRequest ("You picked this mode:\n"
  436.                                  "ModeID  : 0x%lx\n"
  437.                                  "Size    : %ld x %ld\n"
  438.                                  "Depth   : %ld\n"
  439.                                  "Overscan: %ld\n"
  440.                                  "AutoScroll %s",
  441.                                  "Right", NULL, NULL,
  442.                                  scrmodereq->DisplayID,
  443.                                  scrmodereq->DisplayWidth,
  444.                                  scrmodereq->DisplayHeight,
  445.                                  scrmodereq->DisplayDepth,
  446.                                  scrmodereq->OverscanType,
  447.                                  scrmodereq->AutoScroll ? "On" : "Off");
  448.             else
  449.                 rtEZRequest ("You didn't pick a screen mode.", "Nope", NULL, NULL);
  450.  
  451.             rtFreeRequest (scrmodereq);
  452.             }
  453.         else
  454.             rtEZRequest ("Out of memory!", "Oh boy!", NULL, NULL);
  455.         }
  456.     rtEZRequestTags ("That's it!\n"
  457.                           "Hope you enjoyed the demo", "_Sure did", NULL, NULL,
  458.                           RT_Underscore, '_', TAG_END);
  459.  
  460.     /* free all resources */
  461.     CloseLibrary ((struct Library *)ReqToolsBase);
  462.  
  463.     return 0;
  464. }
  465.  
  466. #ifdef DOHOOKS
  467. /********
  468. * HOOKS *
  469. ********/
  470. #ifdef __GCC__
  471. BOOL file_filterfunc (struct Hook *hook,struct rtFileRequester *filereq,struct FileInfoBlock *fib)
  472. #else
  473. BOOL __asm __saveds file_filterfunc (
  474.     REG __a0 struct Hook *hook,
  475.     REG __a2 struct rtFileRequester *filereq,
  476.     REG __a1 struct FileInfoBlock *fib
  477.     )
  478. #endif __GCC__
  479. {
  480.     myputs (fib->fib_FileName);
  481.     myputs ("\n");
  482.     return (TRUE);
  483. }
  484.  
  485. #ifdef __GCC__
  486. BOOL font_filterfunc (struct Hook *hook,struct rtFontRequester *fontreq,struct TextAttr *textattr)
  487. #else
  488. BOOL __asm __saveds font_filterfunc (
  489.     REG __a0 struct Hook *hook,
  490.     REG __a2 struct rtFontRequester *fontreq,
  491.     REG __a1 struct TextAttr *textattr
  492.     )
  493. #endif __GCC__
  494. {
  495.     myputs (textattr->ta_Name);
  496.     myputs ("\n");
  497.     return (TRUE);
  498. }
  499.  
  500. #ifdef __GCC__
  501. BOOL vol_filterfunc (struct Hook *hook,struct rtFileRequester *filereq,struct rtVolumeEntry *volentry)
  502. #else
  503. BOOL __asm __saveds vol_filterfunc (
  504.     REG __a0 struct Hook *hook,
  505.     REG __a2 struct rtFileRequester *filereq,
  506.     REG __a1 struct rtVolumeEntry *volentry
  507.     )
  508. #endif __GCC_
  509. {
  510.     myputs (volentry->Type == DLT_DEVICE ? "(Volume) " : "(Assign) ");
  511.     myputs (volentry->Name);
  512.     myputs ("\n");
  513.     return (TRUE);
  514. }
  515. #endif DOHOOKS
  516.